package com.demo.project_template.util;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {

    /**
     * 获取今天是周几
     * @return 周几
     */
    public static int todayOfWeek(){
        LocalDate today = LocalDate.now(ZoneId.systemDefault());
        DayOfWeek dayOfWeek = today.getDayOfWeek();
        return dayOfWeek.getValue();
    }

    /**
     * 计算向前或者向后几天的日期
     * @param days 加的天数（正数为向后移动，负数为向前移动）
     * @return 计算后的日期
     */
    public static Date changeDateByDay(Date date, Integer days){
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.DATE,days);
        date = cal.getTime();
        return date;
    }


    public static Date changeDateByMonth (Date date,Integer months){
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.MONTH,months);
        date = cal.getTime();
        return date;
    }

    public static Date changeDateByYear (Date date,Integer year){
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.YEAR,year);
        date = cal.getTime();
        return date;
    }
}
